<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="google-site-verification" content="VGgQeH6NiuAKspyCFT7dqUNmNhg6RJoMYQXErdy0jgE" />
  <meta name="baidu-site-verification" content="code-yNmdsKJ9GP" />
  
  
  <meta name="keywords" content="Elasticsearch,elasticsearch,搭建，环境搭建,">
  
  
  <meta name="description" content="Elasticsearch 环境搭建">
  
  <title>
    1.Elasticsearch 环境搭建 |
    
    思远程序
  </title>
  <!-- Icon -->
  
    <link rel="shortcut icon" href="/favicon.ico">
    
  
<link rel="stylesheet" href="/css/style.css">

  
  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<script src="/js/pace.min.js"></script>

<meta name="generator" content="Hexo 6.2.0"></head>

<body>
  <main class="content">
    <section class="outer">
  <article id="post-1. ElaticSearch 环境搭建" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
      

<h1 class="article-title" itemprop="name">
  1.Elasticsearch 环境搭建
</h1>



    </header>
    

    
    <div class="article-meta">
      <a href="/2022/07/23/1.%20ElaticSearch%20%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" class="article-date">
  <time datetime="2022-07-23T01:00:00.000Z" itemprop="datePublished">2022-07-23</time>
</a>
      
<div class="article-category">
  <a class="article-category-link" href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E6%A1%86%E6%9E%B6/">分布式框架</a>
</div>

    </div>
    

    
    
<div class="tocbot"></div>

    

    <div class="article-entry" itemprop="articleBody">
      
      
      
      <p>官网下载解压即可：</p>
<p><a target="_blank" rel="noopener" href="https://www.elastic.co/">https://www.elastic.co</a></p>
<p>下载速度慢可使用下面链接：</p>
<p>ElasticSearch: <a target="_blank" rel="noopener" href="https://mirrors.huaweicloud.com/elasticsearch/?C=N&O=D">https://mirrors.huaweicloud.com/elasticsearch/?C=N&O=D</a><br>logstash: <a target="_blank" rel="noopener" href="https://mirrors.huaweicloud.com/logstash/?C=N&O=D">https://mirrors.huaweicloud.com/logstash/?C=N&O=D</a></p>
<span id="more"></span>

<h3 id="熟悉配置文件"><a href="#熟悉配置文件" class="headerlink" title="熟悉配置文件"></a>熟悉配置文件</h3><p><img src="https://siyit-blog.oss-cn-hangzhou.aliyuncs.com/images/2022202207231047032.png" alt="img"></p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">bin 启动文件</span><br><span class="line">config 配置文件</span><br><span class="line">	log4j2 日志配置文件</span><br><span class="line">	jvm.options java 虚拟机配置文件</span><br><span class="line">	elaticsearch.yml elaticsearch配置文件 默认端口：<span class="number">9200</span></span><br><span class="line"><span class="keyword">data</span> ElaticSearch存储数据文件目录，可手动指定</span><br><span class="line">jdk </span><br><span class="line">lib jar包</span><br><span class="line">logs 日志文件</span><br><span class="line">modules 模块</span><br><span class="line">plugins 插件</span><br></pre></td></tr></table></figure>

<p>双击启动 elaticsearch.bat ，测试访问 <a target="_blank" rel="noopener" href="http://localhost:9200/">http://localhost:9200</a><br><img src="https://siyit-blog.oss-cn-hangzhou.aliyuncs.com/images/2022202207231047390.png" alt="image.png"></p>
<h3 id="安装-ElaticSearch-head"><a href="#安装-ElaticSearch-head" class="headerlink" title="安装 ElaticSearch-head"></a>安装 ElaticSearch-head</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git://github.com/mobz/elasticsearch-head.git</span><br><span class="line"><span class="built_in">cd</span> elasticsearch-head</span><br><span class="line">npm install</span><br><span class="line">npm run start</span><br><span class="line"></span><br><span class="line"><span class="comment"># 会遇到跨域问题，配置文件中进行修改</span></span><br><span class="line"><span class="comment"># --------------------------------- 设置允许跨域处理() -----------------------------------</span></span><br><span class="line">http.cors.enabled: <span class="literal">true</span></span><br><span class="line">http.cors.allow-origin: <span class="string">&quot;*&quot;</span></span><br></pre></td></tr></table></figure>

<h3 id="安装-Kibana"><a href="#安装-Kibana" class="headerlink" title="安装 Kibana"></a>安装 Kibana</h3><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">官网地址下载：</span><br><span class="line">kibana: https://mirrors.huaweicloud.com/kibana/?C=N&amp;O=D</span><br><span class="line"></span><br><span class="line">解压后修改配置文件</span><br><span class="line">vim ./config/kibana.yml</span><br><span class="line">server.port: <span class="number">5601</span></span><br><span class="line">elasticsearch.hosts: [<span class="string">&quot;http://localhost:9200&quot;</span>]</span><br><span class="line">kibana.index: <span class="string">&quot;.kibana&quot;</span></span><br><span class="line">i18n.locale: <span class="string">&quot;zh-CN&quot;</span> </span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动</span></span><br><span class="line">./bin/kibana</span><br><span class="line"></span><br><span class="line">访问测试</span><br><span class="line">http://localhost:<span class="number">5601</span></span><br></pre></td></tr></table></figure>

<p><img src="https://siyit-blog.oss-cn-hangzhou.aliyuncs.com/images/2022202207231047869.png" alt="img"></p>
<p><img src="https://siyit-blog.oss-cn-hangzhou.aliyuncs.com/images/2022202207231049249.png" alt="img"></p>
<h4 id="cat-API"><a href="#cat-API" class="headerlink" title="cat API"></a>cat API</h4><figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">/_cat/allocation #查看单节点的shard分配整体情况</span><br><span class="line">/_cat/shards #查看各shard的详细情况</span><br><span class="line">/_cat/shards/&#123;index&#125; #查看指定分片的详细情况</span><br><span class="line">/_cat/master #查看master节点信息</span><br><span class="line">/_cat/nodes #查看所有节点信息</span><br><span class="line">/_cat/indices #查看集群中所有index的详细信息</span><br><span class="line">/_cat/indices/&#123;index&#125; #查看集群中指定index的详细信息</span><br><span class="line">/_cat/segments #查看各index的segment详细信息,包括segment名, 所属shard, 内存(磁盘)占用大小, 是否刷盘</span><br><span class="line">/_cat/segments/&#123;index&#125;#查看指定index的segment详细信息</span><br><span class="line">/_cat/count #查看当前集群的doc数量</span><br><span class="line">/_cat/count/&#123;index&#125; #查看指定索引的doc数量</span><br><span class="line">/_cat/recovery #查看集群内每个shard的recovery过程.调整replica。</span><br><span class="line">/_cat/recovery/&#123;index&#125;#查看指定索引shard的recovery过程</span><br><span class="line">/_cat/health #查看集群当前状态：红、黄、绿</span><br><span class="line">/_cat/pending_tasks #查看当前集群的pending task</span><br><span class="line">/_cat/aliases #查看集群中所有alias信息,路由配置等</span><br><span class="line">/_cat/aliases/&#123;alias&#125; #查看指定索引的alias信息</span><br><span class="line">/_cat/thread_pool #查看集群各节点内部不同类型的threadpool的统计信息,</span><br><span class="line">/_cat/plugins #查看集群各个节点上的plugin信息</span><br><span class="line">/_cat/fielddata #查看当前集群各个节点的fielddata内存使用情况</span><br><span class="line">/_cat/fielddata/&#123;fields&#125; #查看指定field的内存使用情况,里面传field属性对应的值</span><br><span class="line">/_cat/nodeattrs #查看单节点的自定义属性</span><br><span class="line">/_cat/repositories #输出集群中注册快照存储库</span><br><span class="line">/_cat/templates #输出当前正在存在的模板信息</span><br></pre></td></tr></table></figure>
<h3 id="安装-Ik-分词器"><a href="#安装-Ik-分词器" class="headerlink" title="安装 Ik 分词器"></a>安装 Ik 分词器</h3><p>下载对应版本：<a target="_blank" rel="noopener" href="https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.7.0">https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.7.0</a> 并解压，并重命名为<code>ik</code><br><code>docker cp /Users/wzq/Downloads/ik elasticsearch:/usr/share/elasticsearch/plugins/</code><br>重启<code>docker restart docker</code></p>
<p><strong>验证：</strong></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"># ES 的默认分词设置是standard，会单子拆分</span><br><span class="line">POST _analyze</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;analyzer&quot;</span><span class="punctuation">:</span> <span class="string">&quot;standard&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;中华人民共和国&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line"></span><br><span class="line"># ik_smart<span class="punctuation">:</span>会做最粗粒度的拆分</span><br><span class="line">POST _analyze</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;analyzer&quot;</span><span class="punctuation">:</span> <span class="string">&quot;ik_smart&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;中华人民共和国&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line"># ik_max_word<span class="punctuation">:</span>会将文本做最细粒度的拆分</span><br><span class="line">POST _analyze</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;analyzer&quot;</span><span class="punctuation">:</span> <span class="string">&quot;ik_max_word&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;中华人民共和国&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 创建索引时可以指定IK分词器作为默认分词器</span><br><span class="line">PUT /es_db</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;settings&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;index&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;analysis.analyzer.default.type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;ik_max_word&quot;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line"># 查看创建好的索引</span><br><span class="line">GET /es_db</span><br></pre></td></tr></table></figure>

<h4 id="分词的目的"><a href="#分词的目的" class="headerlink" title="分词的目的"></a>分词的目的</h4><p>内容分词，提取关键字根据关键字建立倒排索引。</p>
<p>在搜搜时，对所有的内容进行分词，然后在倒排索引中查找，最终定位到具体信息。</p>
<h4 id="自定义分词"><a href="#自定义分词" class="headerlink" title="自定义分词"></a>自定义分词</h4><p><strong>IKAnalyzer.cfg.xml</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version=<span class="string">&quot;1.0&quot;</span> encoding=<span class="string">&quot;UTF-8&quot;</span>?&gt;</span></span><br><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">properties</span> <span class="keyword">SYSTEM</span> <span class="string">&quot;http://java.sun.com/dtd/properties.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">comment</span>&gt;</span>IK Analyzer 扩展配置<span class="tag">&lt;/<span class="name">comment</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--用户可以在这里配置自己的扩展字典 --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;ext_dict&quot;</span>&gt;</span>siyuan.dic<span class="tag">&lt;/<span class="name">entry</span>&gt;</span></span><br><span class="line">	 <span class="comment">&lt;!--用户可以在这里配置自己的扩展停止词字典--&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">entry</span> <span class="attr">key</span>=<span class="string">&quot;ext_stopwords&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">entry</span>&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--用户可以在这里配置远程扩展字典 --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &lt;entry key=&quot;remote_ext_dict&quot;&gt;words_location&lt;/entry&gt; --&gt;</span></span><br><span class="line">	<span class="comment">&lt;!--用户可以在这里配置远程扩展停止词字典--&gt;</span></span><br><span class="line">	<span class="comment">&lt;!-- &lt;entry key=&quot;remote_ext_stopwords&quot;&gt;words_location&lt;/entry&gt; --&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>siyuan.dic</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">打工人</span><br></pre></td></tr></table></figure>

<p><img src="https://siyit-blog.oss-cn-hangzhou.aliyuncs.com/images/2022202207231050053.png" alt="img"></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://siyit.gitee.io/2022/07/23/1.%20ElaticSearch%20%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/" data-id="cl6bukbsp0001su6f7cmaa8mc" class="article-share-link">
        分享
      </a>
      
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Elasticsearch/" rel="tag">Elasticsearch</a></li></ul>

    </footer>

  </div>

  
  
<nav class="article-nav">
  
  <a href="/2022/07/23/2.%20Elasticsearch%20%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/" class="article-nav-link">
    <strong class="article-nav-caption">前一篇</strong>
    <div class="article-nav-title">
      
      2.Elasticsearch 快速入门
      
    </div>
  </a>
  
  
  <a href="/2012/12/21/chushibiao/" class="article-nav-link">
    <strong class="article-nav-caption">后一篇</strong>
    <div class="article-nav-title">出师表</div>
  </a>
  
</nav>

  

  
  
<div class="vcomments" id="vcomments"></div>

<script src="https://unpkg.com/valine/dist/Valine.min.js"></script>

<script>
  new Valine({
    el: '#vcomments',
    appId: 'A7Ny5JW4l2XoShLWoQfpND2b-gzGzoHsz',
    appKey: 'lTbAjSoXEDQETkbAcE4zpYpu',
    notify: 'true',
    verify: 'true',
    avatar: 'identicon',
    pageSize: '10',
    placeholder: '请输入...'
  })
</script>

  
  

</article>
</section>
    <footer class="footer">
  <div class="outer">
    <div class="float-right">
      <ul class="list-inline">
  
  <li><i class="fe fe-smile-alt"></i> <span id="busuanzi_value_site_uv"></span></li>
  
  <li><i class="fe fe-bookmark"></i> <span id="busuanzi_value_page_pv"></span></li>
  
</ul>
    </div>
    <ul class="list-inline">
      <li>思远程序 &copy; 2022</li>
      
        <li></li>
      
      <li>Powered by <a href="http://hexo.io/" target="_blank">Hexo</a></li>
      <li>theme  <a target="_blank" rel="noopener" href="https://github.com/zhwangart/hexo-theme-ocean">Ocean</a></li>
    </ul>
  </div>
</footer>
  </main>
  <aside class="sidebar">
    <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/hexo.svg" alt="思远程序"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/recommend">推荐</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/gallery">相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/favorites">收藏</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link nav-item-search" title="搜索">
        <i class="fe fe-search"></i>
        搜索
      </a>
    </li>
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      <div class="totop" id="totop">
  <i class="fe fe-rocket"></i>
</div>
    </li>
    <li class="nav-item">
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="fe fe-feed"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
  </aside>
  
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/jquery.justifiedGallery.min.js"></script>


<script src="/js/lazyload.min.js"></script>


<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script src="/fancybox/jquery.fancybox.min.js"></script>





<script src="/js/tocbot.min.js"></script>


<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
  });
</script>



<script src="/js/ocean.js"></script>

</body>

</html>